using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class KyThiQG_DAO
    {
        public DataSet SoLuongDauRot()
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection con = new SqlConnection();
                DataProvider dp = new DataProvider();
                con = dp.ConnectionData();
                con.Open();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_SoLuongDauRot";

                cmd.ExecuteNonQuery();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);

                con.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            return ds;
        }

        public DataSet TinhDoanhThu()
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection con = new SqlConnection();
                DataProvider dp = new DataProvider();
                con = dp.ConnectionData();
                con.Open();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_TKDoanhThu";

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                con.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            return ds;
        }

        public void DoanhThu(ref Double DoanhThu)
        {
            try
            {
                SqlConnection con = new SqlConnection();
                DataProvider dp = new DataProvider();
                con = dp.ConnectionData();
                con.Open();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_DoanhThu";

                cmd.Parameters.Add("@DoanhThu", SqlDbType.Money);
                cmd.Parameters["@DoanhThu"].Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                DoanhThu = Convert.ToDouble(cmd.Parameters["@DoanhThu"].Value);
                con.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable DSKyThi()
        {
            try
            {
                DataTable dt = new DataTable();
                SqlConnection con = new SqlConnection();
                DataProvider dp = new DataProvider();
                con = dp.ConnectionData();
                con.Open();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_LayDSKyThi";

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                con.Close();
                return dt;
            }
            catch (SqlException e)
            {
                throw e;
            }

        }
    }
}
